import request from '@/utils/request'

/**
 * 结算页面-生成订单-根据购物车选中商品
 * @returns
 */
export const createOrder = () => request({
  url: '/member/order/pre'
})
/**
 * 结算页面-生成订单-根据订单商品
 * @returns
 */
export const repurchaseOrder = (orderId) => request({
  url: `/member/order/repurchase/${orderId}`
})

/**
 * 添加收货地址
 * @param {Object} from
 * @returns
 */
// 添加收货地址
export const addAddress = (from) => request({
  url: '/member/address',
  method: 'POST',
  data: from
})

/**
 * 修改收货地址
 * @param {Object} from
 * @returns
 */
// 修改收货地址
export const editAddress = (from) => request({
  url: `/member/address/${from.id}`,
  method: 'PUT',
  data: from
})

/**
 * 结算页面-提交订单
 * @param
 * @returns
 */
export const submitOrder = reqParams => request({
  url: '/member/order',
  method: 'POST',
  data: reqParams
})
/**
 * 获取订单详情
 * @param {String} orderId -订单Id
 * @returns
 */
export const findOrderDetail = (orderId) => request({
  url: `/member/order/${orderId}`

})
/**
 * 获取订单列表
 * @param {String} page -页码
 * @param {String} oage -每页条数
 * @param {String} orderState -订单状态
 * @returns
 */
export const findOrderList = ({ page = 1, pageSize = 10, orderState = 0 }) => request({
  url: '/member/order',
  params: { page, pageSize, orderState }
})

/**
 * 取消订单
 * @param {String} orderId -订单ID
 *
 * @returns
 */
export const cancelOrder = ({ cancelReason, orderId }) => request({
  url: `/member/order/${orderId}/cancel`,
  method: 'PUT',
  data: { cancelReason }
})

/**
 * 删除订单
 * @param {String} orderId - 订单Id
 * @returns
 */
export const deleteOrder = (orderId) => request({
  url: '/member/order',
  method: 'DELETE',
  data: {
    ids: [orderId]
  }
})

// 模拟发货
/// member/order/consignment/:id

/**
 * 确认收货
 * @param {Stirng} orderId -订单编号
 * @returns
 */
export const confirmOrder = (orderId) => request({
  url: `/member/order/${orderId}/receipt`,
  method: 'PUT'
})

/**
 *
 * @param {String} orderId -订单Id
 * @returns
 */
export const logisticOrder = (orderId) => request({
  url: `/member/order/${orderId}/logistics`
})
